﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:Fluent="clr-namespace:Fluent" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d">

  <ResourceDictionary.MergedDictionaries>
    <ResourceDictionary Source="pack://application:,,,/Fluent;component\Themes\Office2010\Controls\ApplicationMenuItem.xaml"/>
  </ResourceDictionary.MergedDictionaries>

  <ControlTemplate x:Key="ApplicationMenuButtonControlTemplate" TargetType="{x:Type Fluent:ApplicationMenu}">
    <ControlTemplate.Resources>
      <Style BasedOn="{StaticResource ApplicationMenuStyle}" TargetType="{x:Type Fluent:MenuItem}"/>
    </ControlTemplate.Resources>
        <Grid>
          <ContentControl x:Name="buttonContent" Width="{Binding ActualWidth, ElementName=PART_ButtonBorder}" Height="{Binding ActualHeight, ElementName=PART_ButtonBorder}" Margin="0,0,0,1">
          <Border x:Name="PART_ButtonBorder" MinWidth="56" Height="23" CornerRadius="2,2,0,0" Background="{TemplateBinding Background}">
            <Border x:Name="border1" BorderThickness="1,1,1,0" CornerRadius="2,2,0,0">
                <Border.BorderBrush>
                    <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                        <GradientStop Color="#997C7C7C" Offset="0"/>
                        <GradientStop Color="#7F848484" Offset="1"/>
                    </LinearGradientBrush>
                </Border.BorderBrush>
                <Border x:Name="border" BorderThickness="1,1,1,0" CornerRadius="1,1,0,0">
                    <Border.BorderBrush>
                        <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                            <GradientStop Color="#72FFFFFF" Offset="0"/>
                            <GradientStop Color="#4CFFFFFF" Offset="1"/>
                        </LinearGradientBrush>
                    </Border.BorderBrush>
                    <Border.Background>
                        <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                            <GradientStop Color="#3FFFFFFF" Offset="0"/>
                            <GradientStop Offset="1" Color="#3FFFFFFF"/>
                            <GradientStop Offset="0.5"/>
                        </LinearGradientBrush>
                    </Border.Background>
                    <Grid>
                        <Rectangle x:Name="rectangle_Copy" StrokeThickness="0">
                            <Rectangle.Fill>
                                <RadialGradientBrush Center="0.5,0.0" GradientOrigin="0.5,0.0" RadiusX="0.501" RadiusY="0.319">
                                    <GradientStop Color="#59FFFFFF"/>
                                    <GradientStop Offset="1"/>
                                </RadialGradientBrush>
                            </Rectangle.Fill>
                        </Rectangle>
                        <Rectangle x:Name="rectangle" StrokeThickness="0">
                            <Rectangle.Fill>
                                <RadialGradientBrush Center="0.5,1.001" GradientOrigin="0.5,1.001" RadiusX="0.496" RadiusY="0.554">
                                    <GradientStop Color="#66FFFFFF" Offset="0.018"/>
                                    <GradientStop Offset="1"/>
                                </RadialGradientBrush>
                            </Rectangle.Fill>
                        </Rectangle>
                        <!--<TextBlock Margin="2,0,2,2" Text="{TemplateBinding Header}" TextWrapping="Wrap" d:LayoutOverrides="Width, Height" HorizontalAlignment="Center" VerticalAlignment="Center"/>-->
                        <ContentPresenter x:Name="contentPresenter" Content="{Binding Header}" VerticalAlignment="Center" HorizontalAlignment="Center"/>
                    </Grid>
                </Border>
            </Border>
        </Border>
          </ContentControl>
          <Popup 
            x:Name="PART_Popup"
            Placement="Relative"
            PlacementTarget="{Binding ElementName=buttonContent}"
            IsOpen="{TemplateBinding IsDropDownOpen}"
            AllowsTransparency="True" 
            Focusable="False"
            PopupAnimation="Fade" Margin="0,0,-4,0" VerticalAlignment="Top" Grid.ColumnSpan="2">
                <Grid 
              Name="DropDown"
              SnapsToDevicePixels="True" Margin="0" VerticalAlignment="Top">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="*"/>
                        <RowDefinition Height="10"/>
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="*"/>
                        <ColumnDefinition Width="10"/>
                    </Grid.ColumnDefinitions>
                    <Rectangle HorizontalAlignment="Left" VerticalAlignment="Top" Width="4" Height="4" Grid.Row="1" Grid.Column="1" StrokeThickness="0" Margin="-1,-1,0,0">
                        <Rectangle.Fill>
                            <RadialGradientBrush RadiusX="0.984" Center="0.017,0.002" GradientOrigin="0.017,0.002" RadiusY="1">
                                <GradientStop Color="#3F000000" Offset="0"/>
                                <GradientStop Color="#00000000" Offset="1"/>
                            </RadialGradientBrush>
                        </Rectangle.Fill>
                    </Rectangle>
                    <Rectangle StrokeThickness="0" HorizontalAlignment="Left" Margin="-1,3,0,0" VerticalAlignment="Top" Width="4" Height="4" Grid.Column="1" Grid.Row="0">
                        <Rectangle.Fill>
                            <RadialGradientBrush Center="0.032,1.01" GradientOrigin="0.032,1.01" RadiusX="0.984" RadiusY="1">
                                <GradientStop Color="#3F000000" Offset="0"/>
                                <GradientStop Color="#00000000" Offset="1"/>
                            </RadialGradientBrush>
                        </Rectangle.Fill>
                    </Rectangle>
                    <Rectangle StrokeThickness="0" HorizontalAlignment="Left" Margin="3,-1,0,0" VerticalAlignment="Top" Width="4" Height="4" Grid.Column="0" Grid.Row="1">
                        <Rectangle.Fill>
                            <RadialGradientBrush Center="0.996,0.027" GradientOrigin="0.996,0.027" RadiusX="0.984" RadiusY="1">
                                <GradientStop Color="#3F000000" Offset="0"/>
                                <GradientStop Color="#00000000" Offset="1"/>
                            </RadialGradientBrush>
                        </Rectangle.Fill>
                    </Rectangle>
                    <Rectangle StrokeThickness="0" HorizontalAlignment="Stretch" Margin="7,-1,1,0" VerticalAlignment="Top" Width="Auto" Height="4" Grid.Column="0" Grid.Row="1">
                        <Rectangle.Fill>
                            <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0" MappingMode="RelativeToBoundingBox">
                                <GradientStop Color="#3F000000" Offset="0"/>
                                <GradientStop Color="#00000000" Offset="1"/>
                            </LinearGradientBrush>
                        </Rectangle.Fill>
                    </Rectangle>
                    <Rectangle StrokeThickness="0" HorizontalAlignment="Left" Margin="-1,7,0,1" VerticalAlignment="Stretch" Width="4" Height="Auto" Grid.Column="1" Grid.Row="0">
                        <Rectangle.Fill>
                            <LinearGradientBrush EndPoint="1,0.5" StartPoint="0,0.5" MappingMode="RelativeToBoundingBox">
                                <GradientStop Color="#3F000000" Offset="0"/>
                                <GradientStop Color="#00000000" Offset="1"/>
                            </LinearGradientBrush>
                        </Rectangle.Fill>
                    </Rectangle>
                    <Border x:Name="PART_DropDownBorder" MinWidth="{TemplateBinding ActualWidth}" SnapsToDevicePixels="True" Background="{DynamicResource ContextMenuBarBackgroundBrush}" BorderBrush="{DynamicResource ContextMenuBarBorderBrush}" BorderThickness="1" CornerRadius="1" Grid.ColumnSpan="1" d:LayoutOverrides="Width, Height" HorizontalAlignment="Stretch" VerticalAlignment="Top">
                        <Grid Width="Auto" Height="Auto" HorizontalAlignment="Stretch" VerticalAlignment="Top">
                          <Grid HorizontalAlignment="Stretch" VerticalAlignment="Top">
                              <Grid.RowDefinitions>
                                <RowDefinition Height="Auto"/>
                                <RowDefinition Height="*"/>
                                <RowDefinition Height="Auto" MinHeight="17"/>
                              </Grid.RowDefinitions>
                              <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto" MinWidth="100"/>
                                <ColumnDefinition Width="*"/>
                              </Grid.ColumnDefinitions>
                              <Border Grid.Row="0" Grid.ColumnSpan="2" BorderThickness="0,0,0,1" BorderBrush="{DynamicResource ContextMenuSeparatorBrush}" Margin="0" Background="{DynamicResource RibbonBackgoundBrush}">
                                <ContentControl x:Name="buttonOnPopupContent" HorizontalAlignment="Left" Margin="-1,-1,0,0"/>
                              </Border>
                                
                              <Fluent:MenuPanel ScrollViewer.VerticalScrollBarVisibility="Auto" Grid.Row="1" Grid.Column="0" x:Name="PART_MenuPanel" IsItemsHost="True" KeyboardNavigation.DirectionalNavigation="Cycle"/>
                              <Border Grid.Row="1" Grid.Column="1" BorderThickness="1,0,0,0" BorderBrush="{DynamicResource ContextMenuSeparatorBrush}" Width="{TemplateBinding RightPaneWidth}" Background="{DynamicResource GalleryBackgroundBrush}">
                                <ContentPresenter ContentSource="RightPaneContent" x:Name="PART_RightContentPresenter"/>
                              </Border>
                              <Border Grid.Row="2" Grid.ColumnSpan="2" BorderThickness="0,1,0,0" BorderBrush="{DynamicResource ContextMenuSeparatorBrush}" Background="{DynamicResource RibbonBackgoundBrush}" Margin="0">                                
                                <ContentPresenter ContentSource="FooterPaneContent"/>
                              </Border>  
                            </Grid>
                        </Grid>
                    </Border>
                </Grid>
            </Popup>
        </Grid>

            <ControlTemplate.Triggers>
            <Trigger Property="IsEnabled" Value="False">
                <Setter Property="Opacity" TargetName="PART_ButtonBorder" Value="0.5"/>
                <Setter Property="Effect" TargetName="contentPresenter">
                    <Setter.Value>
                        <Fluent:GrayscaleEffect/>
                    </Setter.Value>
                </Setter>
            </Trigger>
            <Trigger Property="Header" Value="{x:Null}">
              <Setter Property="Tag" TargetName="contentPresenter" Value="pack://application:,,,/Fluent;component\Themes\Office2010\Images\ApplicationMenu.png"/>
              <Setter Property="Content" TargetName="contentPresenter" Value="{Binding Tag, ElementName=contentPresenter, Converter={StaticResource StringToImageConvert}}"/>
                <!--<Setter Property="Content" TargetName="contentPresenter">
                    <Setter.Value>
                        <Image Source="pack://application:,,,/Fluent;component\Themes\Office2010\Images\ApplicationMenu.png" VerticalAlignment="Center" HorizontalAlignment="Center" Stretch="None"/>
                    </Setter.Value>
                </Setter>-->
            </Trigger>
            <MultiTrigger>
                <MultiTrigger.Conditions>
                    <Condition Property="IsMouseOver" Value="True"/>
                </MultiTrigger.Conditions>
                <Setter Property="BorderBrush" TargetName="border1">
                    <Setter.Value>
                        <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                            <GradientStop Color="#A07C7C7C" Offset="0"/>
                            <GradientStop Color="#84848484" Offset="1"/>
                        </LinearGradientBrush>
                    </Setter.Value>
                </Setter>
                <Setter Property="Background" TargetName="border">
                    <Setter.Value>
                        <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                            <GradientStop Color="#4CFFFFFF" Offset="0"/>
                            <GradientStop Color="#25FFFFFF" Offset="1"/>
                            <GradientStop Offset="0.5" Color="#19FFFFFF"/>
                        </LinearGradientBrush>
                    </Setter.Value>
                </Setter>
                <Setter Property="BorderBrush" TargetName="border">
                    <Setter.Value>
                        <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                            <GradientStop Color="#7FFFFFFF" Offset="0"/>
                            <GradientStop Color="#59FFFFFF" Offset="1"/>
                        </LinearGradientBrush>
                    </Setter.Value>
                </Setter>
                <Setter Property="Fill" TargetName="rectangle_Copy">
                    <Setter.Value>
                        <RadialGradientBrush Center="0.5,0" GradientOrigin="0.5,0" RadiusX="0.501" RadiusY="0.319">
                            <GradientStop Color="#66FFFFFF"/>
                            <GradientStop Offset="1"/>
                        </RadialGradientBrush>
                    </Setter.Value>
                </Setter>
                <Setter Property="Fill" TargetName="rectangle">
                    <Setter.Value>
                        <RadialGradientBrush Center="0.5,1.001" GradientOrigin="0.5,1.001" RadiusX="0.496" RadiusY="0.554">
                            <GradientStop Color="#7FFFFFFF" Offset="0.018"/>
                            <GradientStop Offset="1"/>
                        </RadialGradientBrush>
                    </Setter.Value>
                </Setter>
            </MultiTrigger>
            <Trigger Property="IsDropDownOpen" Value="True">
                <Setter Property="Content" TargetName="buttonContent" Value="{x:Null}"/>              
                <Setter Property="Content" TargetName="buttonOnPopupContent" Value="{Binding ElementName=PART_ButtonBorder}"/>

               <Setter Property="CornerRadius" TargetName="PART_ButtonBorder" Value="0"/>
              <Setter Property="CornerRadius" TargetName="border1" Value="0"/>
              <Setter Property="CornerRadius" TargetName="border" Value="0"/>
              
               <Setter Property="Visibility" TargetName="rectangle" Value="Collapsed"/>
                <Setter Property="Visibility" TargetName="rectangle_Copy" Value="Collapsed"/>
                <Setter Property="BorderBrush" TargetName="border1">
                    <Setter.Value>
                        <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                            <GradientStop Color="#99A1A1A1" Offset="0"/>
                            <GradientStop Color="#7F9A9A9A" Offset="1"/>
                        </LinearGradientBrush>
                    </Setter.Value>
                </Setter>
                <Setter Property="BorderBrush" TargetName="border">
                    <Setter.Value>
                        <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                            <GradientStop Color="#4CFFFFFF" Offset="0"/>
                            <GradientStop Color="#72FFFFFF" Offset="1"/>
                        </LinearGradientBrush>
                    </Setter.Value>
                </Setter>
                <Setter Property="Background" TargetName="border">
                    <Setter.Value>
                        <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                            <GradientStop Color="#19FFFFFF" Offset="0"/>
                            <GradientStop Color="#66FFFFFF" Offset="1"/>
                            <GradientStop Offset="0.5" Color="#3FFFFFFF"/>
                        </LinearGradientBrush>
                    </Setter.Value>
                </Setter>
            </Trigger>
            <MultiTrigger>
                <MultiTrigger.Conditions>
                    <Condition Property="IsMouseOver" Value="True" SourceName="PART_ButtonBorder"/>
                    <Condition Property="IsDropDownOpen" Value="True"/>
                </MultiTrigger.Conditions>
                <Setter Property="Visibility" TargetName="rectangle" Value="Collapsed"/>
                <Setter Property="Visibility" TargetName="rectangle_Copy" Value="Collapsed"/>
                <Setter Property="BorderBrush" TargetName="border1">
                    <Setter.Value>
                        <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                            <GradientStop Color="#A0A1A1A1" Offset="0"/>
                            <GradientStop Color="#879A9A9A" Offset="1"/>
                        </LinearGradientBrush>
                    </Setter.Value>
                </Setter>
                <Setter Property="BorderBrush" TargetName="border">
                    <Setter.Value>
                        <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                            <GradientStop Color="#59FFFFFF" Offset="0"/>
                            <GradientStop Color="#7FFFFFFF" Offset="1"/>
                        </LinearGradientBrush>
                    </Setter.Value>
                </Setter>
                <Setter Property="Background" TargetName="border">
                    <Setter.Value>
                        <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                            <GradientStop Color="#26FFFFFF" Offset="0"/>
                            <GradientStop Color="#7FFFFFFF" Offset="1"/>
                            <GradientStop Offset="0.5" Color="#4CFFFFFF"/>
                        </LinearGradientBrush>
                    </Setter.Value>
                </Setter>
            </MultiTrigger>
        </ControlTemplate.Triggers>
    </ControlTemplate>

    <Style TargetType="{x:Type Fluent:ApplicationMenu}">
        <Setter Property="Template" Value="{StaticResource ApplicationMenuButtonControlTemplate}"/>
        <Setter Property="Background" Value="Blue"/>
        <Setter Property="FontFamily" Value="{DynamicResource DefaultFontFamily}"/>
        <Setter Property="FontSize" Value="{DynamicResource DefaultFontSize}"/>
        <Setter Property="Foreground" Value="White"/>
    </Style>

</ResourceDictionary>